import  time,pymysql
from selenium import webdriver
from selenium.webdriver import ChromeOptions
from datetime import datetime
from crawlab import save_item

option = ChromeOptions()
prefs = {
        'profile.default_content_setting_values': {
            'images': 2
        }
    }
# option.headless = True
option.add_experimental_option('prefs', prefs)
option.add_experimental_option('excludeSwitches', ['enable-automation'])
option.add_argument('--ignore-certificate-errors')

print('浏览器加载成功')


us = [ 'https://km.ke.com/ershoufang/wuhua/','https://km.ke.com/ershoufang/panlong/','https://km.ke.com/ershoufang/guandu/', 'https://km.ke.com/ershoufang/wuhua/','https://km.ke.com/ershoufang/panlong/','https://km.ke.com/ershoufang/guandu/']





if __name__ == '__main__':
    option = ChromeOptions()
    driver = webdriver.Chrome(executable_path='chromedriver', options=option)
    a =1
    for u in us:
        try:
            driver.get(u)
            a = a+1
            if a == 2:
                driver.get('https://www.baidu.com/')
                c = 4/0
        except:
            if driver.current_url != u:
                driver.close()
                time.sleep(2)
                driver = webdriver.Chrome(executable_path='chromedriver', options=option)

    
            

            
 